package com.maslyk.invitation.to;

import java.util.EmptyStackException;
import java.util.Stack;

import com.maslyk.invitation.BeanService;
import com.maslyk.invitation.enums.ViewIdentityEnum;

/**
 * 
 * @author kris
 */
public class SessionDataTO {
	private Stack<ViewIdentityEnum> currentViewID = new Stack<ViewIdentityEnum>();

	private ViewIdentityEnum currentPopupViewID = null;

	private boolean readOnly = false;
	
	private boolean formUsesUpload = false;

	public SessionDataTO() {
		currentViewID.push(ViewIdentityEnum.ORDER_LIST);
	}

	public ViewIdentityEnum getCurrentViewID() {
		try {
			return currentViewID.peek();
		} catch (EmptyStackException ese) {
			return ViewIdentityEnum.ORDER_LIST;
		}

	}

	public void pushViewID(ViewIdentityEnum currentViewID) {
		this.currentViewID.push(currentViewID);
	}

	public void popViewID() {
		this.currentViewID.pop();
	}

	public static void setCurrentView(ViewIdentityEnum viewID) {
		SessionDataTO sessionData = (SessionDataTO) BeanService
				.getSessionScopeBean("SessionDataTO");
		sessionData.pushViewID(viewID);
	}

	public static void setCurrentPopupView(ViewIdentityEnum viewID) {
		SessionDataTO sessionData = (SessionDataTO) BeanService
				.getSessionScopeBean("SessionDataTO");
		sessionData.setPopupView(viewID);
	}

	public String getPageToDisplay() {
		return getCurrentViewID().toString();
	}

	public String getPopupPageToDisplay() {
		return currentPopupViewID.toString();
	}

	public void setPopupView(ViewIdentityEnum viewID) {
		currentPopupViewID = viewID;
	}

	public String getPopupPageTitle() {
		return getCurrentViewID().getPageTitle();
	}

	public String getPageTitle() {
		return getCurrentViewID().getPageTitle();
	}

	public boolean isReadOnly() {
		return readOnly;
	}
	
	public static void setReadOnlyView(){
		SessionDataTO sessionData = (SessionDataTO) BeanService
		.getSessionScopeBean("SessionDataTO");
		sessionData.readOnly = true;
	}
	
	public static void setEditView(){
		SessionDataTO sessionData = (SessionDataTO) BeanService
		.getSessionScopeBean("SessionDataTO");
		sessionData.readOnly = false;
	}

	public boolean isFormUsesUpload() {
		return formUsesUpload;
	}

	public void setFormUsesUpload(boolean formUsesUpload) {
		this.formUsesUpload = formUsesUpload;
	}
	
	public static SessionDataTO getThisSessionData(){
		SessionDataTO sessionData = (SessionDataTO) BeanService.getSessionScopeBean("SessionDataTO");
		return sessionData;
	}
	
}
